#include <REGX52.H>
int hour=23,minute=59,seconds=0,count=0;
int sum[8];
void Delay(unsigned int xms)
{
	unsigned char i, j;
	while(xms--)
	{
		i = 2;
		j = 239;
		do
		{
			while (--j);
		} while (--i);
	}
}
void timerInit()
{
	 TMOD|=0x01;
	 TH0=(65536-50000)/256;
	 TL0=(65536-50000)%256;
	 ET0=1;
	 TR0=1;
	 EA=1;
	
}

void ITR_Init()
{
	IT0=1;
	EX0=1;
	PX0=1;
	
	IT1=1;
	EX1=1;
	PX1=1;
}

void SG(int a,int b)
{
	unsigned char Tab[]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F,0x40};
  unsigned char Count[]={0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08};
	P2=Count[a];
	P0=~Tab[b];
	
}
void main()
{
	timerInit();
	ITR_Init();
	while(1)
	{
		SG(0,hour/10);
		Delay(6);
		SG(1,hour%10);
		Delay(6);
		SG(2,10);
		Delay(6);
		SG(3,minute/10);
		Delay(6);
		SG(4,minute%10);
		Delay(6);
		SG(5,10);
		Delay(6);
		SG(6,seconds/10);
		Delay(6);
		SG(7,seconds%10);
		Delay(6);
	}
}

void Timer() interrupt 1
{
	 TH0=(65536-50000)/256;
	 TL0=(65536-50000)%256;
	  
	 count++;
	if(count==20)
	{
		seconds++;
		count=0;
	}
	 if(hour==24)
	 {
		 hour=0;	
	 }	 
	 if(minute==60)
	 {
		 hour++;
		 minute=0;
	 }
	 if(seconds==60)
	 {
		   minute++;
		 seconds=0;
	 }
}
void IRT0() interrupt 0    //外部中断0--->复位
{
	hour=23;
	minute=59;
	seconds=0;
}
void IRT1() interrupt 2    //外部中断1--->暂停
{
	TR0=~TR0;
}